/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q0121.java
 * @Author : WangRuoyu
 * @Date 2023/1/12 10:54
 */

package leetcode;

public class Q0121 {
    public int maxProfit(int[] prices) {
        int res = 0;
        int minValue = 10001;
        for (int price : prices) {
            if (minValue >= price) {
                minValue = price;
            } else {
                res = Math.max(res, price - minValue);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Q0121 sl = new Q0121();
        int[] prices = {7, 1, 5, 3, 6, 4};
        System.out.println(sl.maxProfit(prices));
    }
}
